﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TPCN.DAL;
using TPCN.Common;
using TPCN.Commons;

namespace TPCN.Controls
{
    public partial class uc_login : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            InitPanel();
            if (HttpContext.Current.Session["user"] != null)
            {
                string customerID = HttpContext.Current.Session["user"].ToString();
                KhachHangObj obj = KhachHangDAL.GetByID(customerID);
                string displayname = String.Empty;
                if (obj != null)
                {
                    if (!String.IsNullOrEmpty(obj.Hovaten))
                        displayname = obj.Hovaten;
                    else
                        displayname = StringHelper.GetNameOfEmail(obj.Email);
                    info.Text = displayname;
                    TurnPanelOnOff();
                }
            }
        }

        protected void InitPanel()
        {
            logininfo.Visible = false;
            loginlink.Visible = true;
        }

        protected void btnLogout_Click(object sender, EventArgs e)
        {
            HttpContext.Current.Session.Remove("user");
            TurnPanelOnOff();
            Response.Redirect(Request.RawUrl);
        }

        protected void TurnPanelOnOff()
        {
            logininfo.Visible = !logininfo.Visible;
            loginlink.Visible = !loginlink.Visible;
        }
    }
}